#include <string>
#include <vector>
#include "errors.h"
#include "cmd.h"

namespace cmd
{
    static bool helpOption;
    static bool onlyOption;
    static bool lexerOption;
    static bool parseExpressionsOption;
    static bool parseExpressions2Option;
    static bool parseOption;
    static bool parserWithSymTableOption;

    static std::string filename;
    static std::vector<std::string> options;
    void wrongSyntax()
    {
        helpOption = true;
        throw CCompiler::Errors::CmdOptionsError();
    }
    void parseCmd(int argc, char *argv[])
    {
        for(int i = 1; i < argc; ++i)
            options.push_back(argv[i]);
        for(size_t i = 0; i < options.size(); ++i)
        {
            if(options[i].substr(0, 2) != "--")
            {
                if(!filename.empty()) wrongSyntax();
                filename = options[i];
            }
            else if(options[i] == "--tokenizer-only")
            {
                if(onlyOption) wrongSyntax();
                lexerOption = onlyOption = true;
            }
            else if(options[i] == "--expressions-parser-only")
            {
                if(onlyOption) wrongSyntax();
                parseExpressionsOption = onlyOption = true;
            }
            else if(options[i] == "--expressions-parser2-only")
            {
                if(onlyOption) wrongSyntax();
                parseExpressions2Option = onlyOption = true;
            }
            else if(options[i] == "--parser-only")
            {
                if(onlyOption) wrongSyntax();
                parseOption = onlyOption = true;
            }
            else if(options[i] == "--ParserWithSymTable-only")
            {
                if(onlyOption) wrongSyntax();
                parserWithSymTableOption = onlyOption = true;
            }
        }
    }
    bool needToPrintHelp()
    {
        return options.empty() || helpOption;
    }
    bool lexerOptionEnabled()
    {
        return lexerOption;
    }
    bool parseExpressionsOptionEnabled()
    {
        return parseExpressionsOption;
    }
    bool parseExpressions2OptionEnabled()
    {
        return parseExpressions2Option;
    }
    bool parseOptionEnabled()
    {
        return parseOption;
    }
    bool parserWithSymTableOptionEnabled()
    {
        return parserWithSymTableOption;
    }
    bool onlyOptionEnabled()
    {
        return onlyOption;
    }
    
    std::string getFilename()
    {
        return filename;
    }
}

